home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Information / CSMP Digest / volume 3 / csmp-digest-v3-099 < prev    next >
Text File  |  1995-12-31  |  66KB  |  1,699 lines

  1. C.S.M.P. Digest             Fri, 02 Jun 95       Volume 3 : Issue 99
  2.  
  3. Today's Topics:
  4.  
  5.         Async MacTCP PowerPC woes...
  6.         C++ Working Paper
  7.         Error Checking
  8.         How to program network licence
  9.         Keyboard events from a background application
  10.         MIDI Books & other stuff
  11.         New PowerPC Assembly Language Book
  12.         Printing Styled TextEdit
  13.         QuickDraw 3D Info
  14.         QuickTake API?
  15.         WakeUpProcess at Interrupt Time
  16.  
  17.  
  18.  
  19. The Comp.Sys.Mac.Programmer Digest is moderated by Francois Pottier
  20. (pottier@clipper.ens.fr).
  21.  
  22. The digest is a collection of article threads from the internet newsgroups
  23. comp.sys.mac.programmer.help, csmp.tools and csmp.misc. It is designed for
  24. people who read news semi-regularly and want an archive of the discussions.
  25. If you don't know what a newsgroup is, you probably don't have access to
  26. it. Ask your systems administrator(s) for details. If you don't have access
  27. to news, you may still be able to post messages to the group by using a
  28. mail server like anon.penet.fi (mail help@anon.penet.fi for more
  29. information).
  30.  
  31. Each issue of the digest contains one or more sets of articles (called
  32. threads), with each set corresponding to a 'discussion' of a particular
  33. subject.  The articles are not edited; all articles included in this digest
  34. are in their original posted form (as received by our news server at
  35. nef.ens.fr).  Article threads are not added to the digest until the last
  36. article added to the thread is at least two weeks old (this is to ensure that
  37. the thread is dead before adding it to the digest).  Article threads that
  38. consist of only one message are generally not included in the digest.
  39.  
  40. The digest is officially distributed by two means, by email and ftp.
  41.  
  42. If you want to receive the digest by mail, send email to listserv@ens.fr
  43. with no subject and one of the following commands as body:
  44.     help                                Sends you a summary of commands
  45.     subscribe csmp-digest Your Name     Adds you to the mailing list
  46.     signoff csmp-digest                 Removes you from the list
  47. Once you have subscribed, you will automatically receive each new
  48. issue as it is created.
  49.  
  50. The official ftp info is //ftp.dartmouth.edu/pub/csmp-digest.
  51. Questions related to the ftp site should be directed to
  52. scott.silver@dartmouth.edu.
  53.  
  54. -------------------------------------------------------
  55.  
  56. >From wem53067@uxa.cso.uiuc.edu (TheBard)
  57. Subject: Async MacTCP PowerPC woes...
  58. Date: Sun, 07 May 1995 06:40:28 -0600
  59. Organization: Bard 'O Matic Software
  60.  
  61. Ok, I'm having quite a frustrating problem. It seems that my asyc calls
  62. are randomly causing my Powermac to crash. It hard to tell exactly whats
  63. going on, but I know the crash is not hapening untill the exact moment an
  64. async call is made.
  65.  
  66. Here is my code:
  67.  
  68. OSErr LowTCPWaitForConnection(StreamPtr streamPtr,byte timeout,ip_addr
  69. *remoteHost,
  70.          tcp_port *remotePort,ip_addr *localHost,tcp_port *localPort,
  71.          Boolean async,TCPiopb **returnBlock)
  72. {
  73.    OSErr err;
  74.    TCPiopb *pBlock;
  75.    TCPIOCompletionUPP  myProc;
  76.    
  77.    myProc = NewTCPIOCompletionProc((ProcPtr)NotifyConnected);
  78.    
  79.    if ((err = NewBlock(&pBlock)) != noErr)
  80.       return err;
  81.    
  82.    pBlock->csCode = TCPPassiveOpen;
  83.    //pBlock->ioResult = 1;
  84.    pBlock->ioCompletion = myProc;
  85.    pBlock->tcpStream = streamPtr;
  86.    pBlock->csParam.open.ulpTimeoutValue = timeout;
  87.    pBlock->csParam.open.ulpTimeoutAction = 0;
  88.    pBlock->csParam.open.validityFlags = 0xC0;
  89.    pBlock->csParam.open.commandTimeoutValue = timeout;
  90.    pBlock->csParam.open.remoteHost = 0;
  91.    pBlock->csParam.open.remotePort = 0;
  92.    pBlock->csParam.open.localPort = *localPort;
  93.    pBlock->csParam.open.tosFlags = 0;
  94.    pBlock->csParam.open.precedence = 0;
  95.    pBlock->csParam.open.dontFrag = 0;
  96.    pBlock->csParam.open.timeToLive = 0;
  97.    pBlock->csParam.open.security = 0;
  98.    pBlock->csParam.open.optionCnt = 0;
  99.    PBControl((ParmBlkPtr)pBlock,true);
  100.    
  101.    return noErr;
  102. }
  103.  
  104. The boolean asynch is true, and all prarametrs are valid.
  105.  
  106. and the asych routine is:
  107.  
  108. void NotifyConnected(TCPiopb myPB)
  109. {
  110.    gTest = TRUE;
  111. }
  112.  
  113. All the async routine is doing is flipping a global Boolean.
  114.  
  115. Now, I guess my first question has to do with the UniversalProcPtr's.
  116. After looking through the Universal Headers, I'm assuming the correct call
  117. is NewTCPIOCompletionProc. If not, what is it? The reason I'm assuming it
  118. is that sometimes when an incoming conntion trigers my async call,
  119. everything works fine. Other times, I get freezes and bombs such as
  120. "Illegal Instruction", ect. So, I think whats hapening is the mode manager
  121. is getting confused or something. I'm not sure at all here. Can someone
  122. help me out?
  123.  
  124. Wayde
  125.  
  126. -- 
  127. ========================================================================
  128. --=The Bard=--
  129. "Just remember, no matter where you go, there you are!"
  130. - ----------------------------------------------------------------------
  131. PGP Public Key available upon request.
  132.  
  133. +++++++++++++++++++++++++++
  134.  
  135. >From hawkfish@halcyon.com (Richard Wesley)
  136. Date: 7 May 1995 21:00:08 GMT
  137. Organization: Punch Deck Consulting
  138.  
  139. In article <wem53067-0705950640280001@antwerp-2.slip.uiuc.edu>
  140. wem53067@uxa.cso.uiuc.edu (TheBard) writes:
  141.  
  142. >    pBlock->csParam.open.optionCnt = 0;
  143. >    PBControl((ParmBlkPtr)pBlock,true);
  144. >    
  145. >    return noErr;
  146. > }
  147.  
  148. Always check the error return for Device manager calls (but ignore them with
  149. File Manager calls)  Probably not your problem, but good practice.
  150.  
  151. > The boolean asynch is true, and all prarametrs are valid.
  152. > and the asych routine is:
  153. > void NotifyConnected(TCPiopb myPB)
  154. > {
  155. >    gTest = TRUE;
  156. > }
  157. > All the async routine is doing is flipping a global Boolean.
  158.  
  159. This should be (TCPiopb *myPB), which might be screwing up your stack in the
  160. Mixed Mode switch.  Also, I suggest using C++ and storing an object pointer in
  161. the pb.userDataPointer - saves globals and makes your code more reusable once
  162. you get this fixed.  Declare the callback as a private static member.
  163.  
  164. > Now, I guess my first question has to do with the UniversalProcPtr's.
  165. > After looking through the Universal Headers, I'm assuming the correct call
  166. > is NewTCPIOCompletionProc. If not, what is it? The reason I'm assuming it
  167. > is that sometimes when an incoming conntion trigers my async call,
  168. > everything works fine. Other times, I get freezes and bombs such as
  169. > "Illegal Instruction", ect. So, I think whats hapening is the mode manager
  170. > is getting confused or something. I'm not sure at all here. Can someone
  171. > help me out?
  172.  
  173. I would guess that this is a timeout problem - sometimes the connection comes
  174. in and sometimes it doesn't.  You are not checking error values in your
  175. callback routine so you always assume that the connection succeeds.  You may
  176. then be using an invalid data structure for the connection.
  177.  
  178. - rmgw
  179.  
  180. - ------------------------------------------------------------------------------
  181.  
  182. Richard Wesley     hawkfish@halcyon.com | "Oh boy!  Did you forget the plot
  183. Punch Deck Consulting  pnchdeck@aol.com |  _again_?"
  184.      Macintosh Software Development     |    - Rocket J. Squirrel
  185. - ------------------------------------------------------------------------------
  186.  
  187.  
  188. +++++++++++++++++++++++++++
  189.  
  190. >From hawkfish@halcyon.com (Richard Wesley)
  191. Date: 9 May 1995 18:07:36 GMT
  192. Organization: Punch Deck Consulting
  193.  
  194. In article <wem53067-0705952026120001@berlin-2.slip.uiuc.edu>
  195. wem53067@uxa.cso.uiuc.edu (TheBard) writes:
  196.  
  197. > Welp, I don't know if its a timeout problem. if it times out, the async
  198. > call should still be made. Here is a question though - If I accidently
  199. > declared the buffer for the stream to be X, and passed the length as x*2,
  200.  
  201. You could easily overwrite random bits of memory, leading to the kinds of
  202. problems you are seeing.  NEVER do this!
  203.  
  204. > would this mess the asyc up? I'm positive it would on the reads and writes
  205. > as soon as I started bushing past the end of the buffer.. but how about
  206. > Asynch?
  207.  
  208. Makes no difference.
  209.  
  210. - rmgw
  211.  
  212. - ------------------------------------------------------------------------------
  213.  
  214. Richard Wesley     hawkfish@halcyon.com | "Oh boy!  Did you forget the plot
  215. Punch Deck Consulting  pnchdeck@aol.com |  _again_?"
  216.      Macintosh Software Development     |    - Rocket J. Squirrel
  217. - ------------------------------------------------------------------------------
  218.  
  219.  
  220. +++++++++++++++++++++++++++
  221.  
  222. >From ari@shore.net (Ari Halberstadt)
  223. Date: Thu, 11 May 1995 01:37:57 -0400
  224. Organization: North Shore Access/Eco Software, Inc; (info@shore.net)
  225.  
  226. In article <wem53067-0705950640280001@antwerp-2.slip.uiuc.edu>,
  227. wem53067@uxa.cso.uiuc.edu (TheBard) wrote:
  228.  
  229. > Ok, I'm having quite a frustrating problem. It seems that my asyc calls
  230. > are randomly causing my Powermac to crash. It hard to tell exactly whats
  231. > going on, but I know the crash is not hapening untill the exact moment an
  232. > async call is made.
  233.  
  234. I don't know exactly what's causing the crash. Last month, I was trying to
  235. do async file manager completion routines on my PPC and the thing crashed
  236. left and right (it was crashing left and right anyway, due to extension
  237. and driver conflicts, but that's another matter). Not to mention the
  238. really weird stuff I was doing (for no good reason, I might add :-)
  239. Anyway, a couple of tricks I've found helpful in debugging this sort of
  240. muck.
  241.  
  242. 1. Always clear the *entire* param block. It's not strictly necessary, but
  243. it can make debugging a lot easier if you forget to clear something that
  244. should be cleared. Later, when it's all debugged, you can remove the extra
  245. intialization. Before filling in the PB fields, just do:
  246.  
  247.    memset(pb, 0, sizeof(TypeOfPB));
  248.  
  249. I do this so often, and can never remember if the zero goes before or
  250. after the sizeof (I had to check in Think Reference), that I have another
  251. function
  252.  
  253.    void memclr(void *p, size_t n);
  254.  
  255. This is good, since on the PPC I can hack a really fast zero assembler
  256. stub, not that I've had to do that yet. Also, I don't get that (discarded)
  257. return value, of which I always feel guilty for not explicitely casting
  258. memset to void. Am I a geek, or what?
  259.  
  260. 2. Always assume every stupid little tiny trivial thing you do will fail. 
  261. This seems to always be true when I program. It will especially fail if
  262. you call the TB, which means checking every single tiny error return (as
  263. mentioned in a prior post) and complaining loudly or *correctly*
  264. recovering, your choice.
  265.  
  266. 3. Don't use a completion routine. Use the asnc call, but just poll for
  267. completion. You can do that in FM calls, so--not having my TCP reference
  268. handy--I assume you can do it in TCP calls. This at least will tell you
  269. whether it's the completion routine or something completely unrelated. In
  270. my experience, 90% of the time it's the completion routine, and 70% of the
  271. time it's something completely unrelated. The completely unrelated events
  272. are usually derived from the current phase of the moon divided by the rate
  273. at which the crickets in Maine are chirping.
  274.  
  275. 4. You've got a mondo memory leak, you're always allocating a new
  276. completion proc and a new parameter block. Here's my trick for OS callback
  277. routines:
  278.  
  279. static pascal t0 FavoriteCallback(t1 p1, t2 p2, ..., tN pN)
  280. {
  281.    ...
  282. }
  283.  
  284. FavoriteUPP uppFavoriteCallback(void)
  285. {
  286.    static FavoriteUPP upp = NULL;
  287.  
  288.    if (! upp) {
  289.       upp = NewFavoriteUPP(FavoriteCallback);
  290.       FailNIL(upp);
  291.    }
  292.    return(upp);
  293. }
  294.  
  295. Lovely, ain't it? Now type this idiom 100 times. Don't you wish you had
  296. generic functions? Anyway, this is great, since you won't go passing a
  297. non-UPP function around, the UPP is allocated only once (and never
  298. again!), etc. I think this would even work in C++ land, since the static
  299. variable would get initialized when the thread of control passed through
  300. the function (or is it the compilation unit?)
  301.  
  302. > Here is my code:
  303. > OSErr LowTCPWaitForConnection(StreamPtr streamPtr,byte timeout,ip_addr
  304. > *remoteHost,
  305. >          tcp_port *remotePort,ip_addr *localHost,tcp_port *localPort,
  306. >          Boolean async,TCPiopb **returnBlock)
  307. > {
  308. >    OSErr err;
  309. >    TCPiopb *pBlock;
  310. >    TCPIOCompletionUPP  myProc;
  311. >    
  312. >    myProc = NewTCPIOCompletionProc((ProcPtr)NotifyConnected);
  313. >    
  314. >    if ((err = NewBlock(&pBlock)) != noErr)
  315. >       return err;
  316. > and the asych routine is:
  317. > void NotifyConnected(TCPiopb myPB)
  318.  
  319. Pascal. Always make callbacks type pascal. Good to make them static
  320. functions as well. Besides the comment in a prior post about not using
  321. globals, don't forget you're going to compile this for 68K. So remember to
  322. set and restore A5 (though you were probably just simplifying the routine
  323. for debugging).
  324.  
  325. > everything works fine. Other times, I get freezes and bombs such as
  326. > "Illegal Instruction", ect. So, I think whats hapening is the mode manager
  327. > is getting confused or something. I'm not sure at all here. Can someone
  328. > help me out?
  329.  
  330. But hey, you have a PowerMac! It doesn't say "Illegal F-line instruction"
  331. anymore. What could be cooler? :-)
  332.  
  333. +++++++++++++++++++++++++++
  334.  
  335. >From scouten@metrowerks.com (Eric Scouten)
  336. Date: Fri, 12 May 1995 00:38:51 -0700
  337. Organization: metrowerks, inc.
  338.  
  339. In article <ari-1105950137570001@198.115.179.207>, ari@shore.net (Ari
  340. Halberstadt) wrote:
  341.  
  342. [TCP debugging suggestions]
  343.  
  344. > 1. Always clear the *entire* param block
  345. > 2. Always assume every stupid little tiny trivial thing you do will fail.
  346.  
  347. These are good suggestions.
  348.  
  349.  
  350. > 3. Don't use a completion routine. Use the asnc call, but just poll for
  351. > completion. 
  352.  
  353. Bad idea. This essentially makes your code synchronous, which is a rather
  354. different case. Furthermore, it will cause your application to exhibit
  355. incorrect behavior or even crash if you use this technique with DNR code
  356. segment calls.
  357.  
  358. Here's why: The DNR code segment often stores intermediate results in the
  359. result parameter field before it decides what the story really is and
  360. calls your completion proc. These are often error codes like the name
  361. server is not responding, which can be very misleading to you. When
  362. working with DNR calls, you *really* have no choice but to write your code
  363. to be truly asynchronous.
  364.  
  365.  
  366. > 4. You've got a mondo memory leak, you're always allocating a new
  367. > completion proc and a new parameter block.
  368.  
  369. Yup.
  370.  
  371. -es
  372.  
  373. __________________________________________________________________________
  374. Eric Scouten                                       Constructor Constructor
  375. scouten@metrowerks.com                                     Metrowerks, Inc.
  376.  
  377.                 OUT OF TOWN May 6-June 4: WWDC & vacation
  378.  
  379. Furthermore, in my mad haste to switch CDs, I dragged the Inside Mac CD-ROM 
  380. icon to the trash and when the Mac ejected it, the tray pushed a glass of 
  381. grape juice off my desk and into my lap. Let that be a lesson to 
  382. development tool vendors: all this would have been avoided with better 
  383. documentation. 
  384.    -Miguel Cruz <mnc@netcom.com>
  385.  
  386. ---------------------------
  387.  
  388. >From kenp@nmrfam.wisc.edu (Ken Prehoda)
  389. Subject: C++ Working Paper
  390. Date: Tue, 16 May 1995 15:04:25 -0500
  391. Organization: Univ of Wisc-Madison, Dept of Biochemistry
  392.  
  393. I thought some of you may be interested to know it is no longer necessary
  394. to purchase the current version of the ISO working paper on C++.  You can
  395. now read the current stab at a standard via this URL:
  396.  
  397. ftp://research.att.com//dist/c++std/WP/
  398.  
  399. The document is in both postscript and acrobat formats.
  400.  
  401. -- 
  402. Ken Prehoda, kenp@nmrfam.wisc.edu
  403.  
  404. ---------------------------
  405.  
  406. >From mcconnel@math.washington.edu
  407. Subject: Error Checking
  408. Date: 9 May 1995 19:42:19 GMT
  409. Organization: University of Washington Department of Mathematics
  410.  
  411. Hello out there...
  412.  
  413. I'd like to know what the hard and fast rules are for Error Checking.
  414.  
  415. Most of the Sample Code I've been looking at does precious little Checking,
  416. and even "real" Documentation says stuff like "You should, of course, 
  417. include Error Checking routines, which we've left out ...";  some Books on 
  418. beginning Programming don't make a big deal out of it, either (perhaps 
  419. because the Sample Programs are designed to be fairly innocuous), so I've 
  420. gotten no real formal training in this particular aspect of Programming.  I 
  421. realize that the basic rule is CHECK EVERYTHING, and I'm fine with that, but 
  422. how do I go about checking everything (and should I truly expect my Code to 
  423. wind up alternating Call/Check/Call/Check/Call/Check... all the way through)?  
  424. Is there any kind of compilation of Error Checks out there, giving a quick 
  425. reference (or even just general guidelines) for exactly how to Check various 
  426. Toolbox Calls or whatnot (perhaps prioritizing things a bit, indicating things 
  427. that one should *always* check immediately or often and things that one can 
  428. check more casually);  or do I just have to flip through the Inside Macintosh 
  429. texts and look up how to check each Call?
  430.  
  431. What say ye?
  432.  
  433. Your help is greatly appreciated.
  434.  
  435.  
  436.  
  437. Regards,
  438.  
  439. Don
  440.  
  441.  
  442.  
  443. Don McConnell
  444. mcconnel@math.washington.edu
  445. University of Washington Department of Mathematics
  446.  
  447.  
  448. +++++++++++++++++++++++++++
  449.  
  450. >From pottier@drakkar.ens.fr (Francois Pottier)
  451. Date: 10 May 1995 10:26:05 GMT
  452. Organization: Ecole Normale Superieure, Paris
  453.  
  454. In article <3oogir$j1t@nntp5.u.washington.edu>,
  455.  <mcconnel@math.washington.edu> wrote:
  456.  
  457. >realize that the basic rule is CHECK EVERYTHING, and I'm fine with that, but 
  458. >how do I go about checking everything (and should I truly expect my Code to 
  459. >wind up alternating Call/Check/Call/Check/Call/Check... all the way through)?
  460.  
  461. Yes. Checking everything is of utmost importance if you write software to
  462. be used by others.
  463.  
  464. If you use C/Pascal your code will actually end up looking as Call/Check/etc.
  465. A better alternative is to use C++, which has exceptions. They can make the
  466. task a lot simpler by making most of the error checking transparent.
  467.  
  468. (That's why I'm impatient to get my hands onto CW6...)
  469.  
  470.  
  471.  
  472. -- 
  473. Francois Pottier                                            pottier@dmi.ens.fr
  474. - ----------------------------------------------------------------------------
  475. Check my WWW page at http://acacia.ens.fr:8080/home/pottier/ ...
  476.  
  477. +++++++++++++++++++++++++++
  478.  
  479. >From sandvik@apple.com (Kent Sandvik)
  480. Date: Thu, 11 May 1995 00:13:30 -0800
  481. Organization: Apple Computer, Inc. Developer Technical Support
  482.  
  483. In article <3oogir$j1t@nntp5.u.washington.edu>,
  484. mcconnel@math.washington.edu wrote:
  485.  
  486. > Hello out there...
  487. > I'd like to know what the hard and fast rules are for Error Checking.
  488. > Most of the Sample Code I've been looking at does precious little Checking,
  489. > and even "real" Documentation says stuff like "You should, of course, 
  490. > include Error Checking routines, which we've left out ...";  some Books on 
  491. > beginning Programming don't make a big deal out of it, either (perhaps 
  492. > because the Sample Programs are designed to be fairly innocuous), so I've 
  493. > gotten no real formal training in this particular aspect of Programming.  I 
  494. > realize that the basic rule is CHECK EVERYTHING, and I'm fine with that, but 
  495. > how do I go about checking everything (and should I truly expect my Code to 
  496. > wind up alternating Call/Check/Call/Check/Call/Check... all the way
  497. through)?  
  498. > Is there any kind of compilation of Error Checks out there, giving a quick 
  499. > reference (or even just general guidelines) for exactly how to Check various 
  500. > Toolbox Calls or whatnot (perhaps prioritizing things a bit, indicating
  501. things 
  502. > that one should *always* check immediately or often and things that one can 
  503. > check more casually);  or do I just have to flip through the Inside Macintosh 
  504. > texts and look up how to check each Call?
  505.  
  506. Check out my QT samples for code for that has *too much error checking*, I
  507. guess  too much is never too much.
  508.  
  509. ftp://ftp.info.apple.com/dts/quicktime/dtsqtutils.May95.hqx
  510.  
  511. Anyway, I test incoming parameters so they are valid, do MemErr() and
  512. similar calls after each trap called, test for error number with
  513. assertions, id absurdum. And some of that extensive testing could be
  514. disabled because the macros operate with flags. In general I don't mind
  515. testing like crasy with d-releases, and disable most of the extensive
  516. testing when shipping something.
  517.  
  518. Cheers, Kent
  519.  
  520. -- 
  521. Kent Sandvik   sandvik@apple.com                  Working with Multimedia stuff...
  522. Apple Developer Technical Support.                                     Private activities on Internet.
  523.  
  524. +++++++++++++++++++++++++++
  525.  
  526. >From dstone@alchemy.chem.utoronto.ca (David Stone)
  527. Date: Thu, 11 May 1995 13:03:58 GMT
  528. Organization: University of Toronto Chemistry
  529.  
  530. In article <sandvik-1105950013300001@17.255.38.116>, sandvik@apple.com
  531. (Kent Sandvik) wrote:
  532. > In article <3oogir$j1t@nntp5.u.washington.edu>,
  533. > mcconnel@math.washington.edu wrote:
  534. > > Hello out there...
  535. > > 
  536. > > I'd like to know what the hard and fast rules are for Error Checking.
  537. > > 
  538. > > Most of the Sample Code I've been looking at does precious little Checking,
  539. > > and even "real" Documentation says stuff like "You should, of course, 
  540. > > include Error Checking routines, which we've left out ...";> 
  541. =====snip======
  542. > Check out my QT samples for code for that has *too much error checking*, I
  543. > guess  too much is never too much.
  544. > ftp://ftp.info.apple.com/dts/quicktime/dtsqtutils.May95.hqx
  545. > Anyway, I test incoming parameters so they are valid, do MemErr() and
  546. > similar calls after each trap called, test for error number with
  547. > assertions, id absurdum. And some of that extensive testing could be
  548. > disabled because the macros operate with flags. In general I don't mind
  549. > testing like crasy with d-releases, and disable most of the extensive
  550. > testing when shipping something.
  551.  
  552. Similar stuff here, although I'm still hazy on assertions.  Example, if
  553. a routine requires a copy of a handle passed to it
  554.  
  555.   DoSomething(Handle data)
  556.   {
  557.      if(data == 0L) return;
  558.  
  559.   }
  560.  
  561. Even better is to return a completion code or error code so that the
  562. calling routine knows whether or not something happened - like the
  563. many Toolbox calls that return an OSErr which are often ignored.  Good
  564. things to check are successful memory allocation and resource loading,
  565. since MemErr/ResErr will be set if there was a problem and the returned
  566. handle will by nil...
  567.  
  568.   myHandle = NewHandle(sizeof(MyData));
  569.   if(myHandle == 0L) return (errorCode);
  570.  
  571. I'm sure there's much more you can do too, like range-checking variables
  572. etc.
  573.  
  574. Dave Stone
  575.  
  576. +++++++++++++++++++++++++++
  577.  
  578. >From Carl R. Osterwald <carl_osterwald@nrel.gov>
  579. Date: 11 May 1995 15:47:45 GMT
  580. Organization: National Renewable Energy Laboratory
  581.  
  582. In article <osterD8Eooq.LzD@netcom.com> David Phillip Oster,
  583. oster@netcom.com writes:
  584. >Here is an "error ladder":
  585. >
  586. >   if(noErr == errCode){ errCode = FSpOpenDF(fs, fsCurPerm, &ref); }
  587. >   if(noErr == errCode){ errCode = GetEOF(ref, &len);}
  588. >   if(noErr == errCode && len < 512){ errCode = eBadPict; }
  589. >   if(noErr == errCode){ len -= 512; errCode = SetFPos(ref, fsFromStart, 512L); }
  590. >   if(noErr == errCode){ ph = (PicHandle) NewHandle(len); errCode = MemError(); }
  591.  
  592. This is all really very good, and I try to do things much like this, but
  593. what if something strange is happening in the middle of the ladder and
  594. you need to find out where in the ladder the problem is occuring? One
  595. solution is to have an integer incremented after each rung.  This
  596. number can be put in the error report so that you can pin down the
  597. exact location.
  598.  
  599. +++++++++++++++++++++++++++
  600.  
  601. >From sandvik@apple.com (Kent Sandvik)
  602. Date: Sun, 14 May 1995 18:56:52 -0800
  603. Organization: Apple Computer, Inc. Developer Technical Support
  604.  
  605. In article <3otbj1$1ak@nrel.nrel.gov>, Carl R. Osterwald
  606. <carl_osterwald@nrel.gov> wrote:
  607.  
  608. > In article <osterD8Eooq.LzD@netcom.com> David Phillip Oster,
  609. > oster@netcom.com writes:
  610. > >Here is an "error ladder":
  611. > >
  612. > >   if(noErr == errCode){ errCode = FSpOpenDF(fs, fsCurPerm, &ref); }
  613. > >   if(noErr == errCode){ errCode = GetEOF(ref, &len);}
  614. > >   if(noErr == errCode && len < 512){ errCode = eBadPict; }
  615. > >   if(noErr == errCode){ len -= 512; errCode = SetFPos(ref,
  616. fsFromStart, 512L); }
  617. > >   if(noErr == errCode){ ph = (PicHandle) NewHandle(len); errCode =
  618. MemError(); }
  619. > This is all really very good, and I try to do things much like this, but
  620. > what if something strange is happening in the middle of the ladder and
  621. > you need to find out where in the ladder the problem is occuring? One
  622. > solution is to have an integer incremented after each rung.  This
  623. > number can be put in the error report so that you can pin down the
  624. > exact location.
  625.  
  626. That's why I assert every time I call a function concerning the OSErr
  627. being noErr. Ex:
  628.  
  629.    anErr = OpenMovieFile(theFSSpec, theRefNum, fsRdPerm);
  630. DebugAssert(anErr == noErr);
  631.  
  632. The Macro used:
  633.  
  634. #if DEBUG
  635. static char gDebugString[256];
  636.  
  637. #define
  638. DebugAssert(condition)                                                     
  639. \
  640.       if (condition)   
  641. NULL;                                                       \
  642.   
  643. else                                                                               
  644. \
  645.   
  646. {                                                                                  
  647. \
  648.       sprintf(gDebugString,"File: %s, Line: %d", __FILE__, __LINE__);         \
  649.      
  650. DebugStr(c2pstr(gDebugString));                                           
  651. \
  652.    }
  653. #else
  654. #define DebugAssert(condition)      NULL
  655. #endif
  656.  
  657. Two things:
  658.  
  659. 1. If DEBUG is not enabled, then the Asserts become NULL statements, and
  660. most decent compilers will optimize away this as well.
  661. 2. If I use MW debugger, if the assert triggers, then I usually drop into
  662. the MW debugger rather than MacsBug. In other words to the exact problem
  663. line. This has saved me so many minutes concerning development it's
  664. incredible (and a big hug to the MW people who implemented this nice
  665. feature for the MW debugger).
  666.  
  667.  
  668. --Kent
  669.  
  670. -- 
  671. Kent Sandvik   sandvik@apple.com                  Working with Multimedia stuff...
  672. Apple Developer Technical Support.                                     Private activities on Internet.
  673.  
  674. +++++++++++++++++++++++++++
  675.  
  676. >From ari@shore.net (Ari Halberstadt)
  677. Date: Sun, 14 May 1995 00:17:04 -0400
  678. Organization: North Shore Access/Eco Software, Inc; (info@shore.net)
  679.  
  680. In article <3oq4bt$rif@nef.ens.fr>, pottier@drakkar.ens.fr (Francois
  681. Pottier) wrote:
  682.  
  683. > In article <3oogir$j1t@nntp5.u.washington.edu>,
  684. >  <mcconnel@math.washington.edu> wrote:
  685. > >realize that the basic rule is CHECK EVERYTHING, and I'm fine with that, but 
  686. > >how do I go about checking everything (and should I truly expect my Code to 
  687. > >wind up alternating Call/Check/Call/Check/Call/Check... all the way through)?
  688. > Yes. Checking everything is of utmost importance if you write software to
  689. > be used by others.
  690. > If you use C/Pascal your code will actually end up looking as Call/Check/etc.
  691. > A better alternative is to use C++, which has exceptions. They can make the
  692. > task a lot simpler by making most of the error checking transparent.
  693. > (That's why I'm impatient to get my hands onto CW6...)
  694.  
  695. Exceptions are the best. They are available in Pascal, at least they were
  696. in 68K land with Apple's special thingy. It's pretty straightforward to
  697. add exceptions in quite portable C (well, I don't know if it really is
  698. portable since it relies on some specific behaviors of volatile and
  699. setjmp/longjmp, though my stuff is mac-only, and it does work and it is
  700. all ANSI C). There are some lovely gotchas with exceptions. Like trying to
  701. use them with threads, since you need to have a separate exception stack
  702. per thread, or else wave your program goodbye. And innocent looking code
  703. like:
  704.  
  705.  ...
  706.  state = HGetState(h);
  707.  HLock(h);
  708.  MayRaiseException();
  709.  HUnlock(h);
  710.  ...
  711.  
  712. may (will) leave a locked block in your heap for the rest of eternity. And
  713. code like:
  714.  
  715.  OSErr MacOSCallBack(...)
  716.  {
  717.    ...
  718.    MayRaisException()
  719.    ...
  720.    return(noErr);
  721.  }
  722.  
  723. could make MacOS angry at you. Better:
  724.  
  725.  OSErr MacOSCallBack(...)
  726.  {
  727.    TRY {
  728.       ...
  729.       MayRaiseException()
  730.       ...
  731.    } CATCH {
  732.       err = error number;
  733.       NOPROPAGATE;
  734.    } ENDTRY;
  735.    return(err);
  736.  }
  737.  
  738. Proper integration with the language helps, so C++ exceptions are a good
  739. thing, though I wish they'd propagate automatically.
  740.  
  741. Anyway, exceptions make software easier to write, understand, and debug.
  742. They're invaluable.
  743.  
  744. +++++++++++++++++++++++++++
  745.  
  746. >From dstone@alchemy.chem.utoronto.ca (David Stone)
  747. Date: Wed, 17 May 1995 13:03:31 GMT
  748. Organization: University of Toronto Chemistry
  749.  
  750. In article <95051423394100973@flugor.si.sub.de>, Andreas Franz
  751. <root@flugor.si.sub.de> wrote:
  752. =====snip=====
  753. > > 
  754. > What i'm doing is something like an easy method: I'm dividing my program into 
  755. > several logical pieces. If i receive an error within on of those routines, i 
  756. > make sure that this routine returns with an error-code and does not change 
  757. > anything. Because this routine has returned an error, the calling routine gets 
  758. > this error-code and returns itself without changing the state entered when 
  759. > beeing called. Doing so ensures that everything has been cleaned up when the 
  760. > program reports the error.
  761. > look at this example:
  762. > void main()
  763. > {
  764. >       OSErr err;
  765. >       err = CreateFile();
  766. >       if(!err)
  767. >       {
  768. >               err=AddSomeData();
  769. >       }
  770. >       CloseFile();
  771. >       if(err)
  772. >       {
  773. >               DeleteFile();
  774. >       }
  775. > }
  776.  
  777. The other advantage here is debugging - each routine can/will generate
  778. a stack frame, allowing you to see how far you've gone through your
  779. code.  EG. to use with MacsBug, you would set compiler options to
  780. always generate stack frames and MacsBug names.  Then if you find
  781. yourself in MacsBug a stack crawl will give you much more info., plus
  782. when you "ip" the code you'll have a much better idea where you are.
  783.  
  784. Dave Stone
  785.  
  786. ---------------------------
  787.  
  788. >From hofstede@inter.NL.net (O.A. ter Hofstede)
  789. Subject: How to program network licence
  790. Date: Mon, 8 May 1995 19:40:28 GMT
  791. Organization: NLnet
  792.  
  793. Hi there!
  794.  
  795. I am looking for a method to prevent my application from running more than
  796. a fixed number of times at the same time within a network environment (ie.
  797. I want to be able to ditribute my program with a network licence for X users).
  798. First I thought about Process to Process Communication, shared lock-files,
  799. etc., but these methods easily break down (program linking turned off, 
  800. read-only volumes, etc.)
  801. Does anyone know a (simple) reliable method I can use? Any ready-to-use
  802. code somewhere?
  803.  
  804. Please send any replies to ter.hofstede@applelink.apple.com.
  805.  
  806. Thanx!
  807.  
  808. Oscar.
  809. -- 
  810. - ----------------------------------------------------------------------------
  811. Oscar ter Hofstede                               Email: hofstede@adgraphics.nl
  812. Phone: +31 5910 40900         Fax: +31 5910 43883          BBS: +31 5910 48529
  813. - ----------------------------------------------------------------------------
  814.  
  815. +++++++++++++++++++++++++++
  816.  
  817. >From nick+@pitt.edu ( nick.c )
  818. Date: Mon, 08 May 1995 16:31:53 -0400
  819. Organization: The Pitt, Chemistry
  820.  
  821. In article <D89ynG.7uG@inter.NL.net>, hofstede@inter.NL.net (O.A. ter
  822. Hofstede) wrote:
  823.  
  824. >I am looking for a method to prevent my application from running more than
  825. >a fixed number of times at the same time within a network environment (ie.
  826. >I want to be able to ditribute my program with a network licence for X users).
  827. >First I thought about Process to Process Communication, shared lock-files,
  828. >etc., but these methods easily break down (program linking turned off, 
  829. >read-only volumes, etc.)
  830.  
  831.  
  832.     The method NOW Utilities, Timbuktu, ChemDraw, and others use
  833.       is to register a ficticious device on the network with the
  834.       name being single serial number of the license.  Other attempts to
  835.       register the same device/serial# give an error that the program
  836.       acts on to deny the user use of the program.  When the program
  837.       quit's (or crashes :-) the fictious device falls off the network,
  838.       and another user can use the license.  
  839.  
  840.     You could do a similiar routine that tries to register 
  841.       a license number, but if it gets an error increments
  842.       the license number, and tries again until it can find
  843.       a unique license or until it increments more than the 
  844.       number of licenses you have it configured for.  Any user 
  845.       can use the program so long as the maximum number of
  846.       licenses aren't being used.
  847.  
  848.     The number of licenses and base license number could be distributed 
  849.       in the form of an encrypted "registration number" that the program 
  850.       prompts for at startup and stores in it's preferences file.  
  851.       That way you only have to distribute a single binary, and site
  852.       licensees can trivially upgrade the number of their licenses
  853.       by getting a new reg number from you and just deleting their
  854.       preference files. 
  855.  
  856.     Chapter 10 of _NIM: Networking_ may be a useful reference
  857.       for this.  Disclaimer: I've never written this kind of
  858.       code.
  859.  
  860.  
  861. >Does anyone know a (simple) reliable method I can use? Any ready-to-use
  862. >code somewhere?
  863.  
  864.     I think "Incognito" with source is availabe on sumex and/or
  865.       umich.  It's source would be a valuable reference.
  866.  
  867. >Please send any replies to ter.hofstede@applelink.apple.com.
  868.  
  869.     Done.
  870.  
  871.  
  872.  ---------------------= Nicholas C. DeMello =--------------------
  873.  
  874.  Internet: nick+@pitt.edu            _/   _/  _/  _/_/_/   _/   _/  
  875.    eWorld: nick                     _/_/ _/  _/  _/   _/  _/_/_/ 
  876.       CIS: 71232,766               _/ _/_/  _/  _/       _/ _/    
  877.      http://www.pitt.edu/~nick/   _/   _/  _/   _/_/_/  _/   _/     
  878.                     
  879. >From hofstede@inter.NL.net (O.A. ter Hofstede)
  880. Subject: How to program network licence
  881. Date: Mon, 8 May 1995 19:37:59 GMT
  882. Organization: NLnet
  883.  
  884. Hi there!
  885.  
  886. I am looking for a method to prevent my application from running more than
  887. a fixed number of times at the same time within a network environment (ie.
  888. I want to be able to ditribute my program with a network licence for X users).
  889. First I thought about Process to Process Communication, shared lock-files,
  890. etc., but these methods easily break down (program linking turned off, 
  891. read-only volumes, etc.)
  892. Does anyone know a (simple) reliable method I can use? Any ready-to-use
  893. code somewhere?
  894.  
  895. Thanx!
  896.  
  897. Oscar.
  898. -- 
  899. - ----------------------------------------------------------------------------
  900. Oscar ter Hofstede                               Email: hofstede@adgraphics.nl
  901. Phone: +31 5910 40900         Fax: +31 5910 43883          BBS: +31 5910 48529
  902. - ----------------------------------------------------------------------------
  903.  
  904. +++++++++++++++++++++++++++
  905.  
  906. >From ray@xfe.dfrc.nasa.gov (Jeff Ray)
  907. Date: Tue, 9 May 1995 17:18:11 GMT
  908. Organization: NASA Dryden FRC
  909.  
  910. In article <D89ynG.7uG@inter.NL.net>, hofstede@inter.NL.net (O.A. ter
  911. Hofstede) wrote:
  912.  
  913. > I am looking for a method to prevent my application from running more than
  914. > a fixed number of times at the same time within a network environment (ie.
  915. > I want to be able to ditribute my program with a network licence for X users).
  916. > First I thought about Process to Process Communication, shared lock-files,
  917. > etc., but these methods easily break down (program linking turned off, 
  918. > read-only volumes, etc.)
  919. > Does anyone know a (simple) reliable method I can use? Any ready-to-use
  920. > code somewhere?
  921.  
  922. The usual method, as another posted said, is to use some kind of NBP scheme.
  923.  
  924. Call Sassafras at (603) 643-3351.  They market the "KeyServer" license
  925. metering system, and they wrote an NBP-based copy protection library for
  926. developers to use so that it would work properly with their system.  (I
  927. guess they got tired of rewriting their software everytime someone cooked
  928. up a new copy protection scheme.)  Contrary to what you might think, it
  929. does not require that either you or your users have a KeyServer
  930. installed.  It just does the right thing if they do.  Cheap (or it was,
  931. last time I checked) and tested, so you can concentrate on your apps
  932. functionallity.
  933.  
  934. Their most recent advertising talks about a LSAPI (License Server API),
  935. which appears to be an emerging industry standard for handling this sort
  936. of thing.
  937.  
  938. Disclaimer:  After doing all this research, I, myself, wound up not using
  939. their library, because to date all my apps have been release without copy
  940. protection.
  941.  
  942. -- 
  943.  Jeff Ray M/S 4840A           Official Correspondence Only:
  944.  NASA/CSC                        Internet:  ray@xfe.dfrc.nasa.gov
  945.  Dryden Flight Research Center
  946.  P. O. Box 273                All Others:
  947.  Edwards, CA 93523-5000          AOL:  Jeff Ray (jeffray@aol.com)
  948.                             eWorld:  JeffRay (jeffray@eworld.com)
  949.   (805) 258-3754     CI$:  70661,2607 (70661.2607@compuserve.com)
  950.  
  951. ---------------------------
  952.  
  953. >From tycho@ele.uri.edu (Tycho Nightingale)
  954. Subject: Keyboard events from a background application
  955. Date: 6 May 1995 15:19:20 GMT
  956. Organization: URI Department of Electrical Engineering
  957.  
  958.  
  959. I am trying to write an application based screensaver, but I am having 
  960. problems determining how long the computer has been idle.  Finding out if 
  961. the mouse has moved is pretty easy, just compare the mouse coordinates 
  962. returned from OSEventAvail, but I am not having much luck determining if 
  963. the keyboard has been idle.
  964.  
  965. So far I have tried long sleep times in WaitNextEvent, and upon getting a 
  966. null event checking the Event Queue for key down events, but unless a 
  967. value of 0 is used for the sleep time this has not worked out.
  968.  
  969. I have read the FAQs, and checked the usual archive sites for ideas but 
  970. haven't found anything, any ideas would be appreciated.
  971.  
  972. Thanks for any help,
  973.  
  974. Tycho Nightingale
  975. tycho@vampyre.acc.uri.edu
  976.  
  977. +++++++++++++++++++++++++++
  978.  
  979. >From mason@cis.umassd.edu (Mason Loring Bliss)
  980. Date: Sun, 7 May 1995 13:17:25 GMT
  981. Organization: University of Massachusetts Dartmouth
  982.  
  983. In <3og41o$3us@egr.uri.edu> tycho@ele.uri.edu (Tycho Nightingale) writes:
  984.  
  985. >I am trying to write an application based screensaver, but I am having 
  986. >problems determining how long the computer has been idle.
  987. [...]
  988. >So far I have tried long sleep times in WaitNextEvent, and upon getting a 
  989. >null event checking the Event Queue for key down events, but unless a 
  990. >value of 0 is used for the sleep time this has not worked out.
  991.  
  992. It doesn't work because you're missing a heck of a lot of keypresses. I'd
  993. use a different method...
  994.  
  995. The way I do it is to patch SystemEvent(). This will not only let you
  996. record the time of every keystroke and mouseup/mousedown, but will also
  997. let you mask the keystroke or mousedown that wakes you up, which you
  998. want to do, right?
  999.  
  1000. Anyway, when you say "application-based," if you really mean "background
  1001. application-based" then you can include the patch in the same file. If
  1002. not, you'll probably have to do a seperate extension, as I don't think
  1003. there's a way to make an application-hosted patch affect anything other
  1004. than the application that applied it.
  1005.  
  1006. Another possibility, if you're not worried about masking events:
  1007.  
  1008. This is from the old-style headers, SysEqu.h:
  1009.  
  1010. KeyTime = 0x186,   /*[GLOBAL VAR]  tickcount when KEYLAST was rec'd [long]*/
  1011. KeyRepTime = 0x18A,/*[GLOBAL VAR]  tickcount when key was last repeated [long]*/
  1012.  
  1013. I can't find the Universal Headers equivalent, but it's got to be around
  1014. somewhere.
  1015.  
  1016. The last thing to worry about with application-based screensavers is this:
  1017. what will you do when there's a modal dialog box on the screen? You won't
  1018. be able to switch to the front.
  1019.  
  1020. Don't get discouraged and you'll end up writing something that works.
  1021.  
  1022. -- 
  1023. Mason Loring Bliss  <>  mason@acheron.middleboro.ma.us  <>  1:109/370.6
  1024. Browse http://www.cis.umassd.edu/~mason for a copy of my PGP Public Key
  1025.  "...all which is forgotten need not necessarily be dead." - Lovecraft
  1026.  
  1027. +++++++++++++++++++++++++++
  1028.  
  1029. >From Steve Sauder <nplains@passport.ca>
  1030. Date: Sat, 13 May 1995 03:01:09 GMT
  1031. Organization: North Plains Systems Inc.
  1032.  
  1033. Tycho:
  1034.  
  1035. It would seem to me that your problem stems from the fact that,
  1036. when using a large sleep time in WaitNextEvent, your background
  1037. app will only be woken up when an event is destined for it (which
  1038. will never happen with user events like keyboard & mousedowns,
  1039. since you're a faceless app...)
  1040.  
  1041. To determine if any key has been pressed, you might want to look
  1042. at using the GetKeys call, which will tell you if, at any given
  1043. time, any keys on the Mac keyboard are down, using an array of
  1044. Boolean values.  This method circumvents the event queue altogether,
  1045. and would therefore seem to be better suited to what you want to
  1046. do.
  1047.  
  1048. BTW, you'll still want to specify a fairly small sleep time in
  1049. WNE, or you won't get any processing time in which to check the
  1050. keys!
  1051.  
  1052. Hope this helps!
  1053.  
  1054. Regards,
  1055. Steve
  1056.  
  1057. - ------------------------------------------------------------------
  1058. Steve Sauder                                     nplains@passport.ca
  1059. North Plains Systems Inc.
  1060. Macintosh Software for Electronic Publishing
  1061.  
  1062.  
  1063.  
  1064. +++++++++++++++++++++++++++
  1065.  
  1066. >From chris-b@cs.auckland.ac.nz (chris-b)
  1067. Date: Sun, 14 May 1995 15:09:46 -1200
  1068. Organization: HyperMedia Unit, Comp Sci, Auckland University
  1069.  
  1070. In article <D8Hxpx.LC7@passport.ca>, Steve Sauder <nplains@passport.ca> wrote:
  1071.  
  1072. >It would seem to me that your problem stems from the fact that,
  1073. >when using a large sleep time in WaitNextEvent, your background
  1074. >app will only be woken up when an event is destined for it (which
  1075. >will never happen with user events like keyboard & mousedowns,
  1076. >since you're a faceless app...)
  1077. >
  1078. >To determine if any key has been pressed, you might want to look
  1079. >at using the GetKeys call, which will tell you if, at any given
  1080. >time, any keys on the Mac keyboard are down, using an array of
  1081. >Boolean values.  This method circumvents the event queue altogether,
  1082. >and would therefore seem to be better suited to what you want to
  1083. >do.
  1084.  
  1085. You could install a (now infamous) jGNEFilter. The jGNEFilter low-mem
  1086. global contains the address of a function that gets called just before
  1087. GNE/WNE returns to any application. This lets you check/modify/generate
  1088. any event you desire. The jGNEFilter mechanism is unusual in that the
  1089. filter you install is active across all applications (not just when you
  1090. are in front). As usual, you need to save the address in jGNEFilter,
  1091. install your own address, and in your filter, do your own stuff and then
  1092. call through to the previous jGNEFilter (if not nil).
  1093.  
  1094. Use archie to find the jGNEHelper sources.
  1095.  
  1096. Chris B
  1097. - ---------------------------------------------------------------------
  1098. NewZealand:AucklandUniversity:ComputerScience:HyperMediaUnit:ChrisBurns
  1099. Internet: chris-b@cs.auckland.ac.nz
  1100. Phone:    +64 9 373-7599 x6194
  1101. Fax:      +64 9 373-7453                         Async, therefore I am.
  1102. - ---------------------------------------------------------------------
  1103.  
  1104. ---------------------------
  1105.  
  1106. >From dstone@alchemy.chem.utoronto.ca (David Stone)
  1107. Subject: MIDI Books & other stuff
  1108. Date: Wed, 17 May 1995 13:38:51 GMT
  1109. Organization: University of Toronto Chemistry
  1110.  
  1111. As promised, here is the info on the MIDI/Pascal book.
  1112.  
  1113. MIDI Programming for the Macintosh
  1114. Steve DeFuria and Joe Scacciaferro
  1115. M&T Books
  1116. 501 Galveston Drive, 
  1117. Redwood City  CA94063  USA
  1118.  
  1119. 1st Ed. 1988, available w/ or w/out disk
  1120. 2nd Ed. 1993?  I tried to order this but couldn't get it.  It was listed
  1121.                in one of those "Books in Print" things but i have no
  1122.                idea if it's actually available.  If anyone has seen it
  1123.                please let me know.
  1124.  
  1125. There is also claimed to be a companion volume for Pascal which is not
  1126. platform-specific by the same authors/publisher entitled "MIDI Programmer's
  1127. Handbook".
  1128.  
  1129. There is tons of useful information about MIDI in general via ftp from
  1130.  
  1131.    ftp.cs.ruu.nl//pub/MIDI/DOC and //pub/MIDI/PROGRAMS/MAC
  1132.  
  1133. - use anonymous or ftp as login id and your email address as password.
  1134. In particular get the docs with names midixxxxxxx or Mac-midi-xxxxx
  1135.  
  1136. I've seen very little for MIDI C programming, and nothing for the Mac.
  1137. The only books seem to be for PCs (Jim Conger's two from 1989, also M&T
  1138. Books).
  1139.  
  1140. >From some of the docs. I've downloaded, there also appears to be a MIDI
  1141. mailing list somewhere, but there was no specific information.  If anyone
  1142. knows about this, maybe they could email me!
  1143.  
  1144. I also downloaded a stuffit file called "midimerger" from somewhere
  1145. (possibly ftp.cs.ruu.nl but it might have been somewhere else - I should
  1146. log these things!).  This contained a freeware MIDI driver for the Mac
  1147. that is callable from Pascal or C using pascal conventions.  It is very
  1148. basic, includes time-stamping and has very few routines, so would be a
  1149. good starting point - the Midi Manager is very intimidating, even with
  1150. the SDK code examples.  (Some of which didn't work when I got version 1.2).
  1151.  
  1152. If anyone else has found good books/sources for MIDI on the Mac, I'd like
  1153. to hear from you.  I know that there are several others here working on
  1154. MIDI projects.  When I have spare time, I'm putting together a Metronome
  1155. package that optionally uses the Sound Manager or MIDI to play the clicks.
  1156. So far so good!
  1157.  
  1158. Dave Stone
  1159.  
  1160. ---------------------------
  1161.  
  1162. >From english@primenet.com (Lawson English)
  1163. Subject: New PowerPC Assembly Language Book
  1164. Date: 9 May 1995 18:03:07 GMT
  1165. Organization: Primenet
  1166.  
  1167. Just got _Optimizing PowerPC Code: Programming the PowerPC Chip in 
  1168. Assembly Language_ by Gary Kacmarcik, Addison-Wesley, ISBN 0-201-40839-2.
  1169.  
  1170. All in all, seems a decent book. Certainly more readable than the 
  1171. Motorola PowerPC 601 User's Handbook that I've been using, and makes MUCH 
  1172. more sense, as well. I've noted one or two minor typos (in the discussion 
  1173. on big- vs little-endian, the illustration (I think) mis-identifies 
  1174. big-endian bit-ordering as little-endian (p. 11) -but I'm dyslexic enough 
  1175. that *I* might be confused here :-/).
  1176.  
  1177. Has interesting discussions on optimization from various perspectives 
  1178. like cache coherency, keeping the pipelines full, that sort of thing. 
  1179. Virtually all of the discussion is about the 601. The 603 is mentioned, 
  1180. but not the 604 or the 620.
  1181.  
  1182. The book is NOT Mac-specific, nor IBM-specific, and in fact, doesn't 
  1183. address assembler details like TOC's, etc., at all.
  1184.  
  1185. All in all, it is the very best book on PowerPC optimization that I have 
  1186. ever read, and I'd be willing to bet dollars to donuts that it is the 
  1187. best available.
  1188.  
  1189. The fact that it is the *only* one available makes me pretty confident...
  1190.  
  1191. Kidding aside, it is pretty good, and looks to be worth the money. Now if 
  1192. someone would just publish a book explaining how to actually *use* PPCAsm 
  1193. with MPW, or if MetroWerks really has added a function-level assembler, 
  1194. I'd be very happy indeed.
  1195.  
  1196. --
  1197. - -----------------------------------------------------------------------------
  1198. Lawson English                            __  __     ____  ___       ___ ____
  1199. english@primenet.com                     /__)/__) / / / / /_  /\  / /_    /
  1200.                                         /   / \  / / / / /__ /  \/ /___  /
  1201. - -----------------------------------------------------------------------------
  1202.  
  1203. +++++++++++++++++++++++++++
  1204.  
  1205. >From Bruce@hoult.actrix.gen.nz (Bruce Hoult)
  1206. Date: Thu, 11 May 1995 14:30:58 +1200 (NZDT)
  1207. Organization: (none)
  1208.  
  1209. english@primenet.com (Lawson English) writes:
  1210. > Kidding aside, it is pretty good, and looks to be worth the money. Now if 
  1211. > someone would just publish a book explaining how to actually *use* PPCAsm 
  1212. > with MPW, or if MetroWerks really has added a function-level assembler, 
  1213. > I'd be very happy indeed.
  1214.  
  1215. What's the problem?  I've always managed to do whatever I've wanted with
  1216. PPCAsm, and either other MPW compilers or CodeWarrior, using the information
  1217. in IM: PowerPC System Software and disassembling sample compiled functions.
  1218.  
  1219. -- Bruce
  1220.  
  1221. ---------------------------
  1222.  
  1223. >From alain@cs.uchicago.edu (Alain Roy)
  1224. Subject: Printing Styled TextEdit
  1225. Date: Wed, 17 May 1995 00:28:33 GMT
  1226. Organization: None
  1227.  
  1228. So I have a program that does some manipulation of Styled TextEdit
  1229. records. The user can type in a bunch of text and play with the
  1230. font/size/style of any part of it.
  1231.  
  1232. I'd like to print the text, with the styles. I'm not worried about being
  1233. too fancy (no adjustable margins or headers on each page, or anything like
  1234. that), I just want the text on the paper, but with the various
  1235. fonts/sizes/styles.
  1236.  
  1237. Do I have to do something gross like walking through the TextEdit data and
  1238. printing it character by character, according to the style? That seems
  1239. slow and painful.
  1240.  
  1241. Or are there some tricks that I might be able to use get the text onto the
  1242. paper?
  1243.  
  1244. Although it's unlikely that users will have more than a page of data, I'd
  1245. like to handle that correctly to.
  1246.  
  1247. Does anyone have any suggestions?
  1248.  
  1249. Thanks in advance.
  1250.  
  1251. -alain
  1252.  
  1253. +++++++++++++++++++++++++++
  1254.  
  1255. >From oster@netcom.com (David Phillip Oster)
  1256. Date: Thu, 18 May 1995 00:52:37 GMT
  1257. Organization: IOpener
  1258.  
  1259. In article <alain-1605951928330001@hammer.uchicago.edu>,
  1260. alain@cs.uchicago.edu (Alain Roy) wrote:
  1261.  
  1262. > So I have a program that does some manipulation of Styled TextEdit
  1263. > records.
  1264.  
  1265. > I'd like to print the text, with the styles.
  1266.  
  1267. What I do is temporarily set the GrafPtr field of the TERec, and thePort
  1268. to the printer port, then call TEUpdate. This has worked for years in
  1269. a commercial product.
  1270. - ------- oster@netcom.com ----------
  1271. "A man hears what he wants to hear and misremembers the rest."
  1272.      -- Paul Simon, ("The Boxer")
  1273.  
  1274. +++++++++++++++++++++++++++
  1275.  
  1276. >From jens_alfke@powertalk.apple.com (Jens Alfke)
  1277. Date: Thu, 18 May 1995 17:29:19 GMT
  1278. Organization: Apple Computer, Inc.
  1279.  
  1280. In article <alain-1605951928330001@hammer.uchicago.edu>,
  1281. alain@cs.uchicago.edu (Alain Roy) wrote:
  1282.  
  1283. > I'd like to print the text, with the styles. I'm not worried about being
  1284. > too fancy (no adjustable margins or headers on each page, or anything like
  1285. > that), I just want the text on the paper, but with the various
  1286. > fonts/sizes/styles.
  1287. > Do I have to do something gross like walking through the TextEdit data and
  1288. > printing it character by character, according to the style? That seems
  1289. > slow and painful.
  1290.  
  1291. Just print it the way you print anything else -- make the print mgr
  1292. incantations to open a printing grafport, then make a TE record in it and
  1293. call TEUpdate. If you're worried about memory usage you can even take your
  1294. existing TE record and munge it to point into the new port with the new
  1295. bounding box.
  1296. Doing nice page breaks so the lines aren't broken across page boundaries
  1297. takes a bit of work. You have to find the nearest line break above the
  1298. page break and clip the viewRect to there, then move the text up by that
  1299. distance when you go to print the next page.
  1300.  
  1301.  
  1302. Jens Alfke_________OpenDoc Geometer_________jens_alfke@powertalk.apple.com
  1303.                                            OpenDoc info: FTP to CILabs.org
  1304.  
  1305.                 LLAMA: NO FEAR OF SPIKES
  1306.  
  1307. +++++++++++++++++++++++++++
  1308.  
  1309. >From jens_alfke@powertalk.apple.com (Jens Alfke)
  1310. Date: Thu, 18 May 1995 17:30:53 GMT
  1311. Organization: Apple Computer, Inc.
  1312.  
  1313. Addendum to my previous posting:
  1314. Don't forget to call FractEnable(true) to turn on fractional widths before
  1315. laying out the text, or the character spacing and margins may be screwed
  1316. up. Be aware that this will change the layout, so if you're using the same
  1317. TE record as on screen you should call TECalText afterwards so TE can
  1318. recompute the line breaks. If you don't use fractional widths on screen,
  1319. call FractEnable(false) when you're done printing.
  1320.  
  1321.  
  1322. Jens Alfke_________OpenDoc Geometer_________jens_alfke@powertalk.apple.com
  1323.                                            OpenDoc info: FTP to CILabs.org
  1324.  
  1325.                 LLAMA: NO FEAR OF SPIKES
  1326.  
  1327. ---------------------------
  1328.  
  1329. >From chaoyang@phakt.usc.edu (Mark Yang)
  1330. Subject: QuickDraw 3D Info
  1331. Date: 5 May 1995 08:45:43 GMT
  1332. Organization: Z-Perception Graphics
  1333.  
  1334. Hi!
  1335.    Does anybody in the net know where I can get some info on QuickDraw 3D
  1336. API and information?  I am so desperate!
  1337.  
  1338. Mark Yang
  1339.  
  1340. +++++++++++++++++++++++++++
  1341.  
  1342. >From jl@ct.ix.de (Jvrn Loviscach)
  1343. Date: Mon, 8 May 1995 12:46:20 GMT
  1344. Organization: Redaktion c't
  1345.  
  1346. In article <chaoyang-0505950150090001@comserv-e-3.usc.edu>, chaoyang@phakt.usc.edu (Mark Yang) says:
  1347.  
  1348. >   Does anybody in the net know where I can get some info on QuickDraw 3D
  1349. >API and information?  I am so desperate!
  1350.  
  1351. Me too!!! But, nontheless, I know the eMail address of
  1352. Apple'e QuickDraw 3D evangelist:S.HOPWOOD@applelink.apple.com
  1353.  
  1354. - -Joern Loviscach
  1355.  
  1356. +++++++++++++++++++++++++++
  1357.  
  1358. >From rodden@cse.ucsc.edu (James Rodden)
  1359. Date: Tue, 09 May 1995 01:31:58 -0700
  1360. Organization: DD/MF & Associates
  1361.  
  1362. In article <D89FH8.Ht2@ix.de>, jl@ct.ix.de (Jvrn Loviscach) wrote:
  1363.  
  1364. >In article <chaoyang-0505950150090001@comserv-e-3.usc.edu>,
  1365. chaoyang@phakt.usc.edu (Mark Yang) says:
  1366. >
  1367. >>   Does anybody in the net know where I can get some info on QuickDraw 3D
  1368. >>API and information?  I am so desperate!
  1369. >
  1370. >Me too!!! But, nontheless, I know the eMail address of
  1371. >Apple'e QuickDraw 3D evangelist:S.HOPWOOD@applelink.apple.com
  1372.  
  1373. If you really want QD3D info avaiable on the net (or any other key
  1374. technology), you should bug the appropriate evangelism group and Apple
  1375. Developer University to publish an overview course on the web. Explain to
  1376. them how benificial it would be to the mac community at large and would
  1377. lure more developers to the Mac platform, etc. There are currently three
  1378. courses online now at
  1379.     http://www.info.apple.com/dev/du/online.html
  1380. and one more waiting to be put on the server. I think these courses are a
  1381. very good thing, if you agree let DU know!!! Unfortunately, the project to
  1382. convert courses to the web has been stalled.
  1383.  
  1384. Disclaimer: this is a "slightly" self-motivated plug. Although I do stand
  1385. to benefit from this project (I'm the one whose been doing the html
  1386. conversions), I feel strongly that this is an important project.
  1387.  
  1388. Jim
  1389.  
  1390. -- 
  1391. J.Rodden, DD/MF & Associates
  1392. Simlab Development Team, Product Architect
  1393.  
  1394. This message contains content that may be offensive to some readers. Some sexual content is not supposed to be viewed by those under 18 according to U.S. laws. You will unfortunately see this type of annoying notice throughout the net. Right now, that's only because we're trying to prove a point. If the amended version of US Senator Exon's "Decency Act", S.314, now tacked onto the telecomm reform bill, passes we'll all be required to put these notices everywhere. Please contact your Congressmen to protest the bill. Please, put warnings like this in your own electronic communications, to spread the word about what the future of the net could be like if we don't act. 
  1395.  
  1396. +++++++++++++++++++++++++++
  1397.  
  1398. >From jeg@apple.com (Julian E Gomez)
  1399. Date: Wed, 17 May 1995 18:17:19 -0800
  1400. Organization: Apple Computer, Inc.
  1401.  
  1402. > In article <chaoyang-0505950150090001@comserv-e-3.usc.edu>,
  1403. chaoyang@phakt.usc.edu (Mark Yang) says:
  1404. > >   Does anybody in the net know where I can get some info on QuickDraw 3D
  1405. > >API and information?  I am so desperate!
  1406.  
  1407. We have started the process of making information available online. Check out
  1408.  
  1409.     http://www.info.apple.com/qd3d/QD3D.HTML
  1410.  
  1411. -- 
  1412. Windows 96 == Macintosh 85
  1413.  
  1414.         Dr. Julian "a tribble took it" Gomez
  1415.         QuickDraw 3D Development Team
  1416.         Apple Computer, Inc.  408/862-1289 or 996-1010
  1417.         jeg@apple.com  julian.g@applelink.apple.com
  1418.  
  1419. ---------------------------
  1420.  
  1421. >From hc7@aixterm1.urz.uni-heidelberg.de (Roland Werner)
  1422. Subject: QuickTake API?
  1423. Date: 4 May 1995 05:28:14 GMT
  1424. Organization: University of Heidelberg, Germany
  1425.  
  1426. Do there exists a programmer interface for the Quicktake100
  1427. digital camera? I want to make photographs periodically and
  1428. paste them in a WWW homepage.
  1429.  
  1430. Thanks!
  1431.  
  1432. Dipl.-Inform. Med. Roland Werner
  1433. Roland_Werner@KRZMAIL.KRZ.UNI-HEIDELBERG.DE
  1434.  
  1435. +++++++++++++++++++++++++++
  1436.  
  1437. >From jonpugh@netcom.com (Jon Pugh)
  1438. Date: Sat, 13 May 1995 20:42:36 GMT
  1439. Organization: Not Organized
  1440.  
  1441. In article <3o9ole$goo@sun0.urz.uni-heidelberg.de>,
  1442. hc7@aixterm1.urz.uni-heidelberg.de (Roland Werner) wrote:
  1443.  
  1444. > Do there exists a programmer interface for the Quicktake100
  1445. > digital camera? I want to make photographs periodically and
  1446. > paste them in a WWW homepage.
  1447.  
  1448. There is an API which is going to be published via APDA and the MacOS
  1449. SDK.  It's basically some glue and driver calls.
  1450.  
  1451. A simple solution is to use AppleScript.  There is a scripting addition
  1452. which provides access to all the camera's functionality.  If you didn't
  1453. get this scripting addition when you bought the camera, then you will
  1454. still need the SDK since it ships with that.  It also ships with
  1455. PhotoFlash 2.0 from Apple (about $99 from US mail order distributers) so
  1456. that is another option.
  1457.  
  1458. The new QuickTake 150 includes both PhotoFlash and the scripting addition.
  1459.  
  1460. Jon
  1461.  
  1462. What are YOU doing to oppose the Microsoft juggernaut?
  1463. ftp://ftp.netcom.com/pub/jo/jonpugh/homepage.html
  1464.  
  1465. ---------------------------
  1466.  
  1467. >From S.W.Lay@damtp.cam.ac.uk (Steve Lay)
  1468. Subject: WakeUpProcess at Interrupt Time
  1469. Date: Wed, 03 May 1995 17:35:50 +0100
  1470. Organization: DAMTP, Cambridge University
  1471.  
  1472. In my faithful IM6 'WakeUpProcess' is listed as being callable at
  1473. interrupt time.  At first I thought this might be useful but....
  1474.  
  1475. My problem is that I have a program which starts an async IO call going
  1476. and would like to go to sleep until the call completes.  (For the sake of
  1477. argument lets say its a PPC call and I'm waiting for a connection.)  I
  1478. thought that by carefully storing my psn in a place which I could find
  1479. again at interrupt time I'd be able to wake-up my sleeping process and do
  1480. the next (non-async) stage in my program.
  1481.  
  1482. Unfortunately, I think I'm getting bitten by a rapid completion.  That is
  1483. my completion routine gets called before I'm suspended so (I guess)
  1484. WakeUpProcess does nothing.  I then unwittingly specify a nice long time
  1485. to go to sleep for, making my response to the IO  v e r y  slow.
  1486.  
  1487. The obvious answer is not to go to sleep for so long but in rapid-fire IO
  1488. situations anything other than 0 would be a visible performance hit.  On
  1489. the other hand the idea of sitting there for hours specifying a sleep
  1490. value of 0 'just in case' seems like a real waste of processor time.  At
  1491. the moment the only strategy I can think of is an 'adaptive sleep size'
  1492. method which tentatively increases the sleep time up to a tolerable
  1493. maximum.
  1494.  
  1495. Anyone got a better solution?  Surely all those clever MacTCP boffins must
  1496. have sorted this kind of thing out?
  1497.  
  1498. -- 
  1499. Steve Lay
  1500. S.W.Lay@damtp.cam.ac.uk
  1501. http://www.amtp.cam.ac.uk/icrd/
  1502.  
  1503. +++++++++++++++++++++++++++
  1504.  
  1505. >From hueras@tiac.net (Jon Hueras)
  1506. Date: Wed, 03 May 1995 22:52:16 -0500
  1507. Organization: The Internet Access Company
  1508.  
  1509. In article <S.W.Lay-0305951735500001@corylus.amtp.cam.ac.uk>,
  1510. S.W.Lay@damtp.cam.ac.uk (Steve Lay) wrote:
  1511.  
  1512. > In my faithful IM6 'WakeUpProcess' is listed as being callable at
  1513. > interrupt time.  At first I thought this might be useful but....
  1514. > My problem is that I have a program which starts an async IO call going
  1515. > and would like to go to sleep until the call completes.  (For the sake of
  1516. > argument lets say its a PPC call and I'm waiting for a connection.)  I
  1517. > thought that by carefully storing my psn in a place which I could find
  1518. > again at interrupt time I'd be able to wake-up my sleeping process and do
  1519. > the next (non-async) stage in my program.
  1520. > Unfortunately, I think I'm getting bitten by a rapid completion.  That is
  1521. > my completion routine gets called before I'm suspended so (I guess)
  1522. > WakeUpProcess does nothing.  I then unwittingly specify a nice long time
  1523. > to go to sleep for, making my response to the IO  v e r y  slow.
  1524.  
  1525. Presumably, when your I/O call completes you record the completion in some
  1526. fashion, either by setting a flag or inserting something into a queue or
  1527. even just relying on ioResult. However you do it, you need some means of
  1528. independently testing whether it's time to wake up your process again and
  1529. you need to ensure that such a test can be performed quickly.
  1530.  
  1531.  Having done this, set up a Time Manager task that periodically performs
  1532. this test and calls WakeUpProcess as needed. Since the test involves
  1533. almost no overhead, you can set the task interval's fuse almost as short
  1534. as you like (as often as a tick even, but I wouldn't make it any shorter
  1535. than a millisecond or you *will* impact the overall system).
  1536.  
  1537. You need to do this because there's no way to *guarantee* that you'll
  1538. sleep before the call completes. However, it doesn't hurt to keep the
  1539. "window of opportunity" as narrow as possible by checking for completion
  1540. just before going to sleep.
  1541.  
  1542. Hope this helps.
  1543.  
  1544.    Jon
  1545.  
  1546. +++++++++++++++++++++++++++
  1547.  
  1548. >From ldo@waikato.ac.nz (Lawrence D9Oliveiro)
  1549. Date: Fri, 05 May 1995 18:28:08 +1200
  1550. Organization: University of Waikato
  1551.  
  1552. In article <S.W.Lay-0305951735500001@corylus.amtp.cam.ac.uk>,
  1553. S.W.Lay@damtp.cam.ac.uk (Steve Lay) wrote:
  1554.  
  1555. >In my faithful IM6 'WakeUpProcess' is listed as being callable at
  1556. >interrupt time.  At first I thought this might be useful but....
  1557. >
  1558. >My problem is that I have a program which starts an async IO call going
  1559. >and would like to go to sleep until the call completes.
  1560.  
  1561. Thot: I recall a "feature" of some past version of the Process Manager,
  1562. whereby it would not switch out a process that had async I/O pending.
  1563. Anybody know if this still applies?
  1564.  
  1565. >Unfortunately, I think I'm getting bitten by a rapid completion.  That is
  1566. >my completion routine gets called before I'm suspended so (I guess)
  1567. >WakeUpProcess does nothing.  I then unwittingly specify a nice long time
  1568. >to go to sleep for, making my response to the IO  v e r y  slow.
  1569.  
  1570. This is what's known as a "race condition". Concurrent-programming
  1571. veterans get bitten by it all the time. :-)
  1572.  
  1573. Ideally, here's the sequence of events you want to have happen:
  1574. * start the async I/O operation.
  1575. * enter critical section (in this case, it means blocking the completion
  1576. routine from running).
  1577. * check if operation has completed. If it has, then leave critical
  1578. section, and skip next step.
  1579. * If operation hasn't completed, then put process to sleep, and leave
  1580. critical section, in a single indivisible operation.
  1581.  
  1582. Interestingly enough, the Thread Manager offers a call which does
  1583. something resembling the last step, but the Process Manager has no
  1584. equivalent functionality.
  1585.  
  1586. Alternatively, it would be nice if the Process Manager maintained a
  1587. one-shot "wake pending" flag that would be set if you called WakeUpProcess
  1588. on a process that wasn't asleep; then the sleep time on the next
  1589. WaitNextEvent call would be forced to zero, so it returned immediately
  1590. (and the flag was cleared).
  1591.  
  1592. >The obvious answer is not to go to sleep for so long but in rapid-fire IO
  1593. >situations anything other than 0 would be a visible performance hit.  On
  1594. >the other hand the idea of sitting there for hours specifying a sleep
  1595. >value of 0 'just in case' seems like a real waste of processor time.
  1596.  
  1597. The issue is not burning CPU time that would otherwise go idle, but
  1598. whether you would hurt the responsiveness of other applications. If all
  1599. you're doing is checking a simple flag and then calling WaitNextEvent
  1600. again, it seems to me the responsiveness hit wouldn't be too bad (unless
  1601. you're on a PowerMac, where you could be incurring lots of mixed-mode
  1602. transitions).
  1603.  
  1604. >  At
  1605. >the moment the only strategy I can think of is an 'adaptive sleep size'
  1606. >method which tentatively increases the sleep time up to a tolerable
  1607. >maximum.
  1608.  
  1609. I can't think of any way to make this foolproof. The race condition could
  1610. still bite you.
  1611.  
  1612. Beginnings of an idea: how about the I/O completion routine starting
  1613. something like a periodic vertical blanking or Time Manager task, that
  1614. kept repeatedly calling WakeUpProcess until it was cancelled by the
  1615. mainline?
  1616.  
  1617. +++++++++++++++++++++++++++
  1618.  
  1619. >From jumplong@aol.com (Jump Long)
  1620. Date: 7 May 1995 13:47:20 -0400
  1621. Organization: America Online, Inc. (1-800-827-6364)
  1622.  
  1623. >In my faithful IM6 'WakeUpProcess' is listed as being callable at
  1624. >interrupt time.  At first I thought this might be useful but....
  1625. >
  1626. >My problem is that I have a program which starts an async IO call going
  1627. >and would like to go to sleep until the call completes.  (For the sake
  1628. >of argument lets say its a PPC call and I'm waiting for a connection.) 
  1629. >I thought that by carefully storing my psn in a place which I could find
  1630. >again at interrupt time I'd be able to wake-up my sleeping process and
  1631. >do the next (non-async) stage in my program.
  1632. >
  1633. >Unfortunately, I think I'm getting bitten by a rapid completion.  That
  1634. >is my completion routine gets called before I'm suspended so (I guess)
  1635. >WakeUpProcess does nothing.  I then unwittingly specify a nice long time
  1636. >to go to sleep for, making my response to the IO  v e r y  slow.
  1637.  
  1638. That's a bug in the Process Manager that has been fixed (I think it was
  1639. fixed with either System 7.1.2 or System Update 3.0). The bug was: If the
  1640. process being awakened by WakeUpProcess was the current process, then the
  1641. WakeUpProcess call was ignored.
  1642.  
  1643. Here's the work-around we (Developer Support) recommend:
  1644.  
  1645. 1) The code that calls WakeUpProcess at interrupt time should set a global
  1646. variable used for the process' WaitNextEvent sleep time to zero. That way,
  1647. if the race condition is encountered, it has minimal effect. The processes
  1648. code that processes the data your interrupt time code is waking it up for
  1649. can set the sleep variable back to the normal value after it has processed
  1650. the data.
  1651.  
  1652. 2) Just before calling WakeUpProcess, the process can check the global
  1653. variable used for sleep time to see it it's zero and if it is, call the
  1654. code that does the processing. This reduces the window of time that the
  1655. race condition can occur in.
  1656.  
  1657. 3) If the application is expecting interrupt time code to wake it up (for
  1658. example, it has a connection open), it should use a "medium-sized" sleep
  1659. value for WaitNextEvent rather than a large sleep value.  For example, if
  1660. my program had an ADSP connection open and the data recieved by ADSP had
  1661. to be processed from my program's event loop, then I might use a sleep
  1662. time of 5 seconds (300 ticks) so that even if I hit the small race
  1663. condition window, the Process Manager will still wake me up after about 5
  1664. seconds.
  1665.  
  1666. - Jim Luther
  1667.  
  1668.  
  1669. ---------------------------
  1670.  
  1671. End of C.S.M.P. Digest
  1672. **********************
  1673.